<?php

namespace App\Console\Commands;

use App\Http\Model\Room;
use App\Http\Model\RoomHostMicro;
use App\Http\Model\RoomMicro;
use App\Http\Services\RoomMsgServices;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Redis;

class CloseAllVolume extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'closeAllVolume';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '全员闭麦';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        try {
            $allOpenedRoomArr = (new Room())->getOpenedRoomIdArr();
            $servicesRoomMsg = new RoomMsgServices();
            $modelRoom = new Room();
            $modelRoomHostMicro = new RoomHostMicro();
            $modelRoomMicro = new RoomMicro();
            foreach($allOpenedRoomArr as $roomId){
                $room = $modelRoom->get_room($roomId);
                $typeId = $room['room_type']['id'];
                $micros = $modelRoomMicro->get_micros($roomId, $typeId);
                for ($i = 0; $i < count($micros); $i++){
                    $modelRoomMicro->volume_close($roomId, $micros[$i]['microphone_id']);
                }
                $servicesRoomMsg->command_micro_volume_close($roomId, -1, 0);
                $servicesRoomMsg->broadcast_micro_volume_close($roomId, -1, 0);



                //主持麦关闭
                $modelRoomHostMicro->set_volume_close($roomId);
                $servicesRoomMsg->command_hostmicro_volume_close($roomId, 0);
                $servicesRoomMsg->broadcast_micro_volume_close($roomId, 0);
            }
        } catch (\Exception $e) {
            echo $e->getMessage();
        }

        return true;
    }
}